<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      .father {
        overflow: hidden;
        width: 300px;
        height: 300px;
        margin: 100px auto;
        background-color: pink;
        text-align: center;
      }

      .son {
        width: 200px;
        height: 200px;
        margin: 50px;
        background-color: purple;
        line-height: 200px;
        color: #fff;
      }
    </style>
  </head>

  <body>
    <div class="father">
      <div class="son">son盒子</div>
    </div>
    <script>
      //阻止冒泡 dom推荐标准 sopPropaggation()
      var son = document.querySelector(".son");
      son.addEventListener(
        "click",
        function (e) {
          alert("son");
          e.stopPropagation(); //stop停止 Propagation传播
          e.cancelBubble = true; //非标准 cancel取消 Bubble 泡泡
        },
        false
      );
      var father = document.querySelector(".father");
      father.addEventListener(
        "click",
        function () {
          alert("father");
        },
        false
      );
      document.addEventListener("click", function () {
        alert("document");
      });
    </script>
  </body>
</html>
